﻿--[[	$Id: readyCheck.lua 3322 2013-06-09 13:29:20Z sdkyron@gmail.com $	]]

local _, caelCore = ...

--[[	Force readycheck warning, auto accept if buffed	]]

caelCore.readycheck = caelCore.createModule("ReadyCheck")

local flasks = {
	-- Cataclysm
	GetSpellInfo(80719),	-- Flask of Steelskin
	GetSpellInfo(80720),	-- Flask of the Draconic Mind
	GetSpellInfo(80721),	-- Flask of the Winds
	GetSpellInfo(80723),	-- Flask of Titanic Strength
	GetSpellInfo(94162),	-- Flask of Flowing Water

	-- Pandaria
	GetSpellInfo(105694),	-- Flask of the Earth
	GetSpellInfo(105691),	-- Flask of the Warm Sun
	GetSpellInfo(105696),	-- Flask of Winter's Bite
	GetSpellInfo(105693),	-- Flask of Falling Leaves
	GetSpellInfo(105689),	-- Flask of Spring Blossoms
}

ReadyCheckListenerFrame:SetScript("OnShow", nil)

local isGuildGroup

caelCore.readycheck:SetScript("OnEvent", function(self, event)
	if event == "READY_CHECK" then
		GuildInstanceDifficulty:HookScript("OnEvent", function(self)
			if self:IsShown() then
				isGuildGroup = true
			else
				isGuildGroup = false
			end
		end)

		self:RegisterEvent("UNIT_AURA")

		PlaySoundFile([=[Sound\Interface\ReadyCheck.wav]=], "Master")

		local food = UnitBuff("player", GetSpellInfo(104280))

		for k, v in pairs(flasks) do
			local flask = UnitBuff("player", k)
		end

		if (not isGuildGroup and food) or (isGuildGroup and flask and food) then
			ReadyCheckFrame:Hide(); ConfirmReadyCheck(1)
			self:UnregisterEvent("UNIT_AURA")
		end
	elseif event == "UPDATE_BATTLEFIELD_STATUS" and StaticPopup_Visible("CONFIRM_BATTLEFIELD_ENTRY") then
		PlaySoundFile([=[Sound\Events\gruntling_horn_bb.ogg]=], "Master") -- Sound\Interface\ReadyCheck.wav
	elseif event == "LFG_PROPOSAL_SHOW" or event == "PARTY_INVITE_REQUEST" or event == "CONFIRM_SUMMON" or event == "PET_BATTLE_QUEUE_PROPOSE_MATCH" then
		PlaySoundFile([=[Sound\Interface\ReadyCheck.wav]=], "Master")
	end
end)

for _, event in next, {
	"READY_CHECK",
	"UPDATE_BATTLEFIELD_STATUS",
	"LFG_PROPOSAL_SHOW",
	"PARTY_INVITE_REQUEST",
	"CONFIRM_SUMMON",
	"PET_BATTLE_QUEUE_PROPOSE_MATCH"
} do
	caelCore.readycheck:RegisterEvent(event)
end